﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Coolite.Ext.Web;
using ENT.GP.Core.Autenticacion;
using ENT.GP.Core.Core;
using ENT.GP.Core.Mail;
//wucViewProyecto1_ctl01
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void Button1_Click(object sender, AjaxEventArgs e)
    {
        try
        {
            Autenticar();
        }
        catch (Exception ex)
        {
            Util.RegistarLog(ex.ToString());
        }
       
    }

    protected void Text2_KeyPress(object sender, AjaxEventArgs e)
    {

        Autenticar();
    }

    private void Autenticar()
    {
        Autenticacion auth;
        auth=Autenticacion.Execute(txtUsername.Text, txtPassword.Text);
        if (auth.Result)
        {

            // Do some Authentication...
            Session["IdUsuario"] = auth.DatosUsuario.Tables[0].Rows[0][0].ToString();
            Session["Usuario"] = txtUsername.Text;
            Session["NombreUsuario"] = string.Format("{0} {1}", auth.DatosUsuario.Tables[0].Rows[0][2].ToString(), auth.DatosUsuario.Tables[0].Rows[0][3].ToString());
            Session["Email"] = auth.DatosUsuario.Tables[0].Rows[0][8].ToString();
            Session["Rol"] = auth.DatosUsuario.Tables[0].Rows[0][10].ToString();
            Session["CRol"] = auth.DatosUsuario.Tables[0].Rows[0][12].ToString();
            Session["IdRol"] = auth.DatosUsuario.Tables[0].Rows[0][9].ToString();
            Session["CodigoRol"] = auth.DatosUsuario.Tables[0].Rows[0][12].ToString();
               
            // Then user send to application
            Response.Redirect("Principal.aspx");
        }
        else
        {
            Ext.Notification.Show(new Notification.Config
                                      {
                                          Title = "Autenticacion",
                                          Icon = Icon.Information,
                                          ShowPin = true,
//                    Tools = new ToolsCollection { new Tool { Type = ToolType.Help, Handler = Ext.MessageBox.Alert("Ayuda", "Obtiene ayuda del sistema").Serialize() } },
                                          Html = "El usuario y/o clave es incorrecto...."
                                      });
        }
    }
}
